package myandroid.net;

import java.sql.Date;
import java.util.Vector;

import android.content.Context;
import myandroid.net.DAO.*;
import myandroid.net.DTO.*;

public class AppData {
	
	private static AppData instance = null;
	
	private Context ctx;
	
	//ten cua DATABASE.
	private static String DATABASE_NAME = "TIM_SEPRO";
	
	//phien ban DATABASE dang dung.
	private static int DATABASE_VERSION = 1;
	
	//cac doi tuong truy cap du lieu xuong cac TABLE trong DATABASE.
	
	private DAO_Project gDaoProject;
	
	private DAO_Setting gDaoSetting;
	
	private DAO_Task gDaoTask;
	
	private DAO_TaskTimeTable gDaoTaskTimeTable;
	
	private DAO_TimeTable gDaoTimeTable;
	
	private AppData()
	{
		gDaoProject = new DAO_Project(this.ctx, DATABASE_NAME, null, DATABASE_VERSION);
		gDaoSetting = new DAO_Setting(this.ctx, DATABASE_NAME, null, DATABASE_VERSION);
		gDaoTask = new DAO_Task(this.ctx, DATABASE_NAME, null, DATABASE_VERSION);
		gDaoTaskTimeTable = new DAO_TaskTimeTable(this.ctx, DATABASE_NAME, null, DATABASE_VERSION);
		gDaoTimeTable = new DAO_TimeTable(this.ctx, DATABASE_NAME, null, DATABASE_VERSION);
		
	}

	public static AppData getInstance() {
		if(AppData.instance == null)
			AppData.instance = new AppData();
		return AppData.instance;
	}

	public static void setInstance(AppData instance) {
		AppData.instance = instance;
	}
	
	// cac ham trong lop DAO_Project-------------------------------------------------------------
	
	//ham them mot project vao trong database
	public void addProject(DTO_Project mProject) {
		
		gDaoProject.addProject(mProject);
	}
	
	//ham update mot project trong database
	public void updateProject(DTO_Project mProject) {
		gDaoProject.updateProject(mProject);
	}
	
	//ham delete mot project trong database
	public void deleteProject(String mProjectID) {
		gDaoProject.deleteProject(mProjectID);
	}
	
	//tim kiem cac project ki tu chua trong ten
	public Vector<DTO_Project> searchProName(String mProName) {
		return gDaoProject.searchProName(mProName);
	}
	
	//tim kiem cac project theo ki tu chua trong mo ta cua project.
	public Vector<DTO_Project> searchProDescrip(String mProDescrip) {
		return gDaoProject.searchProDescrip(mProDescrip);
	}
	
	//ham lay mot project theo ma id cua project
	public DTO_Project getProject(String mProjectID) {
		return gDaoProject.getProject(mProjectID);
	}
	
	//ham lay tat ca project
	public Vector<DTO_Project> getAllProject() {
		return gDaoProject.getAllProject();
	}
	
	//cac ham trong setting.
	
	public void addSetting(DTO_Setting mSetting) {
		gDaoSetting.addSetting(mSetting);
	}
	
	public void updateSetting(DTO_Setting mSetting) {
		gDaoSetting.updateSetting(mSetting);
	}
	
	//xoa Setting theo ngon ngu hien thi
	public void deleteSetting(String mLanguage) {
		gDaoSetting.deleteSetting(mLanguage);
	}
	
	public DTO_Setting getSetting(String mLanguage) {
		return gDaoSetting.getSetting(mLanguage);
	}
	
	public Vector<DTO_Setting> getAllSetting() {
		return gDaoSetting.getAllSetting();
	}
	
	//cac ham trong lop Task
	
	public void addTask(DTO_Task mTask) {
		gDaoTask.addTask(mTask);
	}
	
	public void updateTask(DTO_Task mTask) {
		gDaoTask.updateTask(mTask);
	}
	
	public void deleteTask(String mTaskID) {
		gDaoTask.deleteTask(mTaskID);
	}
	
	public void deleteTask(Date mTaskDate) {
		gDaoTask.deleteTask(mTaskDate);
	}
	
	public void deleteOfParent(String mParentID) {
		gDaoTask.deleteOfParent(mParentID);
	}
	
	//tim kiem task theo mot so ki tu co chua trong ten cua task
	public Vector<DTO_Task> searchTaskName(String mTaskName) {
		return gDaoTask.searchTaskName(mTaskName);
		}
	
	//tim kiem task theo mot so ki tu co chua trong Description cua task
	
	public Vector<DTO_Task> searchTaskDescrip(String mTaskDescrip) {
		return gDaoTask.searchTaskDescrip(mTaskDescrip);
	}
	
	//lay Task theo ma TaskID
	public DTO_Task getTask(String mTaskID) {
		return gDaoTask.getTask(mTaskID);
	}
	
	//lat Task theo ngay tao TaskDate
	public Vector<DTO_Task> getTask(Date mTaskDate) {
		return gDaoTask.getTask(mTaskDate);
	}
	
	// lay cac Task theo ParentID
	public Vector<DTO_Task> getOfParent(String mParentID) {
		return gDaoTask.getOfParent(mParentID);
	}
	
	//lay tat ca cac Task
	public Vector<DTO_Task> getAllTask() {
		return gDaoTask.getAllTask();
	}
	
	//cac ham TaskTimeTable
	
	//them mot TaskTimeTable
	public void addTaskTimeTable(DTO_TaskTimeTable mTaskTimeTable) {
		gDaoTaskTimeTable.addTaskTimeTable(mTaskTimeTable);
	}
	
	//cap nhat mot TaskTimeTable
	public void updateTaskTimeTable(DTO_TaskTimeTable mTaskTimeTable) {
		gDaoTaskTimeTable.updateTaskTimeTable(mTaskTimeTable);
	}
	
	////xoa mot TaskTimeTable theo Id
	public void deleteTaskTimeTable(String mTaskTimeTableID) {
		gDaoTaskTimeTable.deleteTaskTimeTable(mTaskTimeTableID);
	}
	
	//xoa mot TaskTimeTable theo TimeTableID
	public void deleteOfTimeTable(String mTimeTableID) {
		gDaoTaskTimeTable.deleteOfTimeTable(mTimeTableID);
	}
	
	//lay TaskTimeTable theo ma TaskTimeTableID
	public DTO_TaskTimeTable getTaskTimeTable(String mTaskTimeTableID) {
		return gDaoTaskTimeTable.getTaskTimeTable(mTaskTimeTableID);
	}
	
	//lay TaskTimeTable theo ma TimeTableID
	public Vector<DTO_TaskTimeTable> getOfTimeTable(String mTimeTable) {
		return gDaoTaskTimeTable.getOfTimeTable(mTimeTable);
	}
	
	//lay tat ca TaskTimeTable
	public Vector<DTO_TaskTimeTable> getAllTaskTimeTable() {
		return gDaoTaskTimeTable.getAllTaskTimeTable();
	}
	
	//cac ham trong TimeTable
	
	//them mot TimeTable
	public void addTimeTable(DTO_TimeTable mTimeTable) {
		gDaoTimeTable.addTimeTable(mTimeTable);
	}
	
	//cap nhat mot TimeTable
	public void updateTimeTable(DTO_TimeTable mTimeTable) {
		gDaoTimeTable.updateTimeTable(mTimeTable);
	}
	
	//Xoa mot TimeTable
	public void deleteTimeTable(String mTimeTaleID) {
		gDaoTimeTable.deleteTimeTable(mTimeTaleID);
	}
	
	//tim kiem  TimeTable theo ngay bat dau
	public Vector<DTO_TimeTable> searchStatApply(Date StartApply) {
		return gDaoTimeTable.searchStatApply(StartApply);
	}
	
	//tim kiem TimeTable theo ngay ket thuc
	public Vector<DTO_TimeTable> searchEndApply(Date EndApply) {
		return gDaoTimeTable.searchEndApply(EndApply);
	}
	
	//lay mot TimeTable theo ma ID
	public DTO_TimeTable getTimeTable(String mTimeTableID) {
		return gDaoTimeTable.getTimeTable(mTimeTableID);
	}
	
	//lay tat ca TimeTable
	public Vector<DTO_TimeTable> getAllTimeTable() {
		return gDaoTimeTable.getAllTimeTable();
	}

	// cac ham get va set
	
	public DAO_Project getgDaoProject() {
		return gDaoProject;
	}
	
	public void setgDaoProject(DAO_Project gDaoProject) {
		this.gDaoProject = gDaoProject;
	}

	public DAO_Setting getgDaoSetting() {
		return gDaoSetting;
	}

	public void setgDaoSetting(DAO_Setting gDaoSetting) {
		this.gDaoSetting = gDaoSetting;
	}

	public DAO_Task getgDaoTask() {
		return gDaoTask;
	}

	public void setgDaoTask(DAO_Task gDaoTask) {
		this.gDaoTask = gDaoTask;
	}

	public DAO_TaskTimeTable getgDaoTaskTimeTable() {
		return gDaoTaskTimeTable;
	}

	public void setgDaoTaskTimeTable(DAO_TaskTimeTable gDaoTaskTimeTable) {
		this.gDaoTaskTimeTable = gDaoTaskTimeTable;
	}

	public DAO_TimeTable getgDaoTimeTable() {
		return gDaoTimeTable;
	}

	public void setgDaoTimeTable(DAO_TimeTable gDaoTimeTable) {
		this.gDaoTimeTable = gDaoTimeTable;
	}

	public Context getCtx() {
		return ctx;
	}

	public void setCtx(Context ctx) {
		this.ctx = ctx;
	}

}
